﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CraftCellView : MonoBehaviour
{
    public CraftTable this_table;
    public Image Target_Image;
    public Text Target_Name;
    public Text Material_List;
    public Button Craft_Button;
    // 初始化这个单元的数据
    public void SetData(CraftTable table)
    {
        this_table = table;
        Objectinfo TargetObj = ObjectsInfo._instance.getObjectinfobyid(table.targetid);
        Target_Image.overrideSprite = SpriteManager.getInstance().LoadAtlasSprite(TargetObj.atlas_path, TargetObj.icon_name);

        Target_Name.text = TargetObj.name;

        string craft_list = "";
        for(int i = 0; i< table.mat_id.Count; i++)
        {
            Objectinfo MaterialInfo = ObjectsInfo._instance.getObjectinfobyid(table.mat_id[i]);
            craft_list += MaterialInfo.name + " * " + table.mat_num[i].ToString();
            craft_list += ", ";
        }
        Material_List.text = craft_list;
    }
    // 按钮的执行事件
    public void Doing_Craft()
    {
        Inventory._instance.Execute_CraftTable(this_table);
        Craft_List._instance.Refresh_Craft_Table();
    }
    public void Check_if_satisfied()
    {
        bool is_vaild = Inventory._instance.Check_For_CraftTable(this_table);
        if(is_vaild)
        {
            // 理论上应该是素材充足应该可以点击，然后不充足的话应该是灰掉的按钮
            Craft_Button.interactable = true;
        }
        else
        {
            Craft_Button.interactable = false;
        }
    }
}
